//-------------------------------------------------------------------
//	Copyright (c) 2012-2014 Zhirnov Andrey
//	This file is part of the "UXGEN-ES" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#pragma once

namespace Engine
{
namespace _shared_resources_
{

	//
	// Crypt Key
	//

	struct CryptKey
	{
		static uint GenerateUniqueKey ();

		static void BuildKey (const uni_array<uint8> &key0, uint key1);
	};
	

	// GenerateUniqueKey
	inline uint CryptKey::GenerateUniqueKey ()
	{
		using namespace UXMath;
		return ( Random::Int<uint>() ^ (Random::Int<uint>() << 8) ^
				(Random::Int<uint>() << 16) ^ (Random::Int<uint>() << 24) ) | 1;
	}


	// BuildKey
	inline void CryptKey::BuildKey (const uni_array<uint8> &key0, uint key1)
	{
		const uni_array<const uint8>	akey1 = uni_array<const uint8>::FromType( key1 );

		SimpleCryptAlgorithm::Encrypt( key0, akey1 );
	}


}	// _shared_resources_
}	// Engine